package com.bit.springbook.model;

import com.bit.springbook.enums.ResultStatusCodeEnum;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class Result<T> {
    private ResultStatusCodeEnum code;
    private String errMsg;
    private T data;

    public static <T> Result<T> success(T data) {
        return new Result<>(ResultStatusCodeEnum.SUCCESS, "", data);
    }

    public static <T> Result<T> noLogin() {
        return new Result<>(ResultStatusCodeEnum.NO_LOGIN, "用户未登录", null);
    }

    public static <T> Result<T> fail(String msg) {
        return new Result<>(ResultStatusCodeEnum.FAIL, msg, null);
    }
}
